import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
// Callable 接口 类似于runnable接口一样 但是是带有返回值 中间需要用到FutureTask
public class Demo40 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int count = 0;
                System.out.println("hello callable..");
                for(int i = 0; i < 1000; i++ ){
                    count += i;
                }
                return count;
            }
        };
        FutureTask<Integer> task = new FutureTask<>(callable);
        Thread t = new Thread(task);
        t.start();
        t.join();
        System.out.println(task.get());
    }
}
